package com.zxy.health.controller;

import com.zxy.health.dao.HealthCodeDao;
import com.zxy.health.rsp.HealthCodeRsp;
import com.zxy.health.service.HealthCodeService;
import com.zxy.health.service.StudentService;
import com.zxy.health.utils.DateUtils;
import com.zxy.health.utils.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/healthcode")
public class HealthCodeController {
    @Autowired
    HealthCodeService healthCodeService;

    @RequestMapping("/toHealthCode")
    public String toHealthCode(){
        return "healthreport";
    }

    @RequestMapping("/addHealthReport")
    @ResponseBody
    public String addHealthReport(
            @Param("schoolid") String schoolid,
            @Param("name") String name,
            @Param("address") String address,
            @Param("healthcode") int healthcode,
            @Param("classname") String classname,
            @Param("phone") String phone
    ){
        HealthCodeDao healthCodeDao = new HealthCodeDao(StringUtils.getSimpleUUID(),new Date().getTime(),schoolid,name,classname,address,healthcode,phone);
        return healthCodeService.addHealthReport(healthCodeDao);
    }

//    @RequestMapping("/getHealthReport")
//    @ResponseBody
//    public List<HealthCodeDao> getHealthReportBySchoolid(
//            @RequestParam("schoolid")String schoolid
//    ){
//
//        return healthCodeService.getHealthCodeBySchoolid(schoolid);
//    }

    @RequestMapping("/getHealthReport")
    @ResponseBody
    public HealthCodeRsp getHealthReportBySchoolid(
            @RequestParam("schoolid")String schoolid
    ){
        HealthCodeRsp healthCodeRsp = new HealthCodeRsp();
        healthCodeRsp.setList(healthCodeService.getHealthCodeBySchoolid(schoolid));
        return healthCodeRsp;
    }



}
